<!-- 时段无效时间设置 -->
<template>
  <div class="payment-box">
    <strong>时段限制无效设置</strong>
    <el-form :model="ruleForm" :rules="rules" inline ref="ruleForm">
      <el-form-item label="时段限制条件无效时间(小时)" prop="todayFilterInvalidTime">
        <el-input type="number" size="small" v-model.number="ruleForm.todayFilterInvalidTime"></el-input>
        <el-tooltip class="item" effect="dark" content="时段限制条件无效时间：用于释放当前时间无效时间范围内的时段号源的部位限制条件" placement="top-start">
          <i class="el-icon-question"></i>
        </el-tooltip>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="save" size="small">保存</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { invalidsettings, getInvalidsettings } from '@/api/api.js'
export default {
  name: '',
  mixins: [],
  components: {},
  props: {
    hospitalCode: {
      String,
      default: ''
    }
  },
  data() {
    var validateTime = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入时段限制条件无效时间'))
      } else {
        if (value < 0) {
          callback(new Error('无效时间不得小于0小时'))
        } else if (value > 12) {
          callback(new Error('无效时间不得大于12小时'))
        } else {
          callback()
        }
      }
    }
    return {
      ruleForm: {
        feeLimitTime: ''
      },
      rules: {
        todayFilterInvalidTime: [
          { validator: validateTime, trigger: ['blur', 'change'] }
        ]
      }
    }
  },
  watch: {
    hospitalCode() {
      this.getInvalidsettingData()
    }
  },
  computed: {},
  created() {
    this.getInvalidsettingData()
  },
  mounted() {

  },
  methods: {
    save() {
      let params = {
        hospitalCode: this.hospitalCode,
        ...this.ruleForm
      }
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          invalidsettings(params).then(res => {
            if (res && res.code === 10000) {
              this.$message.success('保存成功')
            }
          })
        }
      })
    },
    getInvalidsettingData() {
      getInvalidsettings({ hospitalCode: this.hospitalCode }).then(res => {
        if (res && res.code === 10000) {
          this.ruleForm = res.content
        }
      })
    }
  },
  beforeDestroy() {},
  destroyed() {},
  beforeUpdate() {},
  updated() {}
}
</script>
<style lang='scss' scoped>
.payment-box{
    padding: 24px;
    .el-form{
        margin-top: 20px;
        .el-input{
            width: 180px;
        }
    }
}
</style>
